'use strict';

module.exports = {
  up: async (queryInterface, Sequelize) => {
    // 检查列是否已存在，避免重复添加
    const [results] = await queryInterface.sequelize.query(
      "SHOW COLUMNS FROM reconciliation_results LIKE 'organization_id'"
    );
    
    if (results.length === 0) {
      await queryInterface.addColumn('reconciliation_results', 'organization_id', {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '组织ID'
      });
    }
  },

  down: async (queryInterface, Sequelize) => {
    // 检查列是否存在再删除
    const [results] = await queryInterface.sequelize.query(
      "SHOW COLUMNS FROM reconciliation_results LIKE 'organization_id'"
    );
    
    if (results.length > 0) {
      await queryInterface.removeColumn('reconciliation_results', 'organization_id');
    }
  }
};